package org.dlnu.xeon.service.Impl;

import lombok.extern.slf4j.Slf4j;
import org.dlnu.xeon.dao.UserDao;
import org.dlnu.xeon.domain.User;
import org.dlnu.xeon.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public User selectLoginUser(String number,String password){
        try {
            return userDao.selectLoginUser(number,password);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public List<User> selectAllUser(){
        try {
            return userDao.selectAllUser();
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public User selectUser(Long uid) {
        try {
            return userDao.selectUser(uid);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public User selectUserByName(String name) {
        try {
            return userDao.selectUserByName(name);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public User selectUserByIdNumber(String id_number) {
        try {
            return userDao.selectUserByIdNumber(id_number);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public User selectUserByNumber(String number) {
        try {
            return userDao.selectUserByNumber(number);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public User selectUserByUnit(String unit) {
        try {
            return userDao.selectUserByUnit(unit);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|selectUser] db is error. error = "+ e.toString());
        }
        return null;
    }


    @Override
    public Long insertUser(User user) {
        try {
            user.setJurisdiction(1);
            userDao.insertUser(user);
            return user.getUid();
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|insertUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public Long insertUserAndAdmin(User user) {
        try {
            userDao.insertUser(user);
            return user.getUid();
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|insertUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public User updateUser(User user) {
        try {
            userDao.updateUser(user);
            return userDao.selectUser(user.getUid());
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|updateUser] db is error. error = "+ e.toString());
        }
        return null;
    }

    @Override
    public void deleteUser(Long uid) {
        try {
            userDao.deleteUser(uid);
        } catch (Exception e) {
            log.error("[Boot2022|UserServiceImpl|deleteUser] db is error. error = "+ e.toString());
        }
    }
}
